<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
request.setCharacterEncoding("UTF-8");
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <base href="<%=basePath%>">
<title>合作伙伴配置</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp"></jsp:include>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

	var flag = '';//用于区分是新增还是编辑更新
	history.forward();
	$(document).ready(function() {
		isReadyIframe();
		queryClassification(1);
	});	
	
	function isReadyIframe(){
		var iframe = $(window.parent.document).find("#iframe").length;
		if(iframe==0){
			window.location.href="<%=basePath%>index.jsp";
		}
	}
	
	//点击“查询”
	function queryClassification(pageIndex){
		$.openLoading();
		//按照条件执行查询操作
		$.ajax({
			url : "<%=path%>/channelClassification/queryClassificationInfo?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:{current:pageIndex,size:10},
			dataType:'json',
			success:function(page){
				$.closeLoading();
				if($.validate(page))  return;
				
				if(null != page){
					var buttonStr = "<a href='javascript:void(0)' onClick='viewClassification(this);return false'>编辑</a>&nbsp;<a href='' onClick='deleteClassification(this);return false'>删除</a>";
					var fieldNames = "codeType,code,codeName,codeDesc,status?[{'1':'有效'};{'0':'无效'}],status@TDH";					
					var tableContent = creatTable1(fieldNames,page,null,buttonStr);
					var tableObj = $("#classificationTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage(pageIndex,6,page.maxPage,"1");
					var pageDIV = $("#classificationPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
				}
			}
		});
	}
	/*无此方法,切换分页时会报错*/
	function queryChannelInfo(pageIndex){
		queryClassification(pageIndex);
	}
	//点击“新增/更新”,flag='save'新增,flag='update'更新
	function saveOrUpdateClassification(){
		var codeType = $('#codeType').val();
		var code = $('#code').val();
		var codeName = $('#codeName').val();
		var codeDesc = $('#codeDesc').val();
		var status = $('#status').val();
		//校验数据
		if(code==""){
			$.message("error", "请输入编码!");
			return;
		}
		if(codeName==''){
			$.message("error", "请输入编码名称!");
			return;
		}
		
		//请求参数
		var params = {codeType:codeType,code:code,codeName:codeName,codeDesc:codeDesc,status:status,oldCode:code,oldCodeType:codeType};
		if(flag == 'save'){//新增
			saveClassification(params);
		}else if(flag == 'update'){//更新
			updateClassification(params);
		}
		queryClassification(1);
		closeSaveOrUpdateDiv();
		flag = '';
	}
	
	/*插入新增*/
	function saveClassification(params){
		$.ajax({
			url : "<%=path%>/dictManager/insertDict",
			type : 'POST',
			async : true,
			data:params,
			dataType:'json',
			success:function(obj){
				$.closeLoading();
				if($.validate(obj))  return;
			},
			error: function (jqXHR, textStatus, errorThrown) {
				$.message("error","新增合作伙伴渠道类型失败,请联系管理员!");
			}
		});
	}
	
	/*编辑更新*/
	function updateClassification(params){
		$.ajax({
			url : "<%=path%>/channelClassification/updateDict?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:params,
			dataType:'json',
			success:function(obj){
				$.closeLoading();
				if($.validate(obj))  return;
			},
			error: function (jqXHR, textStatus, errorThrown) {
				$.message("error","编辑失败,请联系管理员!");
			}
		});
	}
	
	/*点击“编辑”回显数据*/
	function viewClassification(classification){
		var tempTr = $(classification).parent().parent()[0];
		var codeType= tempTr.childNodes[0].innerHTML;
		var code = tempTr.childNodes[1].innerHTML;
		var codeName = tempTr.childNodes[2].innerHTML;
		var codeDesc = tempTr.childNodes[3].innerHTML;
		var status = tempTr.childNodes[5].innerHTML;
		//赋值
		$('#codeType').val(codeType);
		$('#code').val(code);
		$('#codeName').val(codeName);
		$('#codeDesc').val(codeDesc);
		$('#status').val(status);
		$("#editClassificationDiv").OpenDiv();
		flag = 'update';//编辑更新
	}
	
	//点击删除按钮
	function deleteClassification(classification){
		var tempTr = $(classification).parent().parent()[0];
		var codeType= tempTr.childNodes[0].innerHTML;
		var code = tempTr.childNodes[1].innerHTML;
		var params = {codeType:codeType,code:code};
		$.ajax({
			url : "<%=path%>/dictManager/delDict",
			type : 'POST',
			async : true,
			data:params,
			dataType:'json',
			success:function(obj){
				$.closeLoading();
				if($.validate(obj))  return;
				queryClassification(1);
			}
		});
	}
	
	/*新增合作伙伴渠道分类*/
	function addClassification(){
		reset();
		flag = 'save';//新增
		$("#editClassificationDiv").OpenDiv();
	}

	/*关闭弹出层,清空已查询的数据*/
	function closeSaveOrUpdateDiv(){
		$("#editClassificationDiv").CloseDiv();
		reset();
	}
	/*重置弹框数据*/
	function reset(){
		$('#codeType').val("channel_classification");//编码类型固定
		$('#code').val("");
		$('#codeName').val("");
		$('#codeDesc').val("");
		$('#status').val("");
		flag = '';
	}
	
</script>
  </head> 
  <body>
  
 	 <div class="current">
           <table class="current_table_1">
             <tbody>
              	<tr class="f2">
	                <td><img src="./images/current_1.jpg"></td>
	                <td class="current_table_1_td">
	                  <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
	                  <span style=" color:#136bab; ">新意健险产品管理
	                  	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>合作伙伴渠道分类
	                  	<span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>维护合作伙伴渠道分类
	                  </span>
                  	</td>
                 	<td><img src="./images/current_3.jpg"></td>
              	</tr>
           	 </tbody>
           </table>
     </div>
  	
  	<table border="1" id="channelTable" class="table_02" style="height:150px">
  		<tr>
			<td>
				<table class="search_table">
					<tr>
						<td width="20%" height=30 nowrap="nowrap">
							<input type="button" value="新增渠道分类字典"  onClick ="addClassification()"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
  		<tr>
  			<td valign="top">
	  			<div id="classificationDIV" style="width:98%;margin:5px" >
			  		<table class="table_02" id="classificationTable">
			  			<thead>
			              	<tr>
			                  	<th style="width:20%">编码类型</th>
			                  	<th style="width:10%">编码</th>
			                  	<th style="width:20%">编码名称</th>
			                  	<th style="width:30%">编码描述</th>
			                  	<th style="width:10%">状态</th>
			                  	<th style="width:10%">操作</th>
			              	</tr>
		              	</thead>
		            </table>
	  				 <div id="classificationPageDIV"  class="page"></div>
	  			</div>
  			</td>
  		</tr>
  	</table>
  	
  	<%--添加或修改Classification相关数据弹出层 --%>
	<div id="editClassificationDiv"  style="display:none;overflow-y:auto; width:40%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeSaveOrUpdateDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02" id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								<tbody>
									<tr>
					                  <td width="30%" style="text-align:right;border-right:0px;">编码类型：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input type="text" id="codeType" class="input_text"  readonly="readonly" style=" background-color: #ccc;width:90%;"></td>
					                </tr>
					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">编码：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="code" type="text" class="input_text" style="width:90%;"></td>
					                </tr>
					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">编码名称：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="codeName" type="text" class="input_text" style="width:90%;"></td>
					                </tr>
 					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">编码描述：&nbsp;</td>
					                  <td width="70%" style="text-align:left"><input id="codeDesc" type="text" class="input_text" style="width:90%;"></td>
					                </tr>
					                <tr>  
					                  <td width="30%" style="text-align:right;border-right:0px;">状态：&nbsp;</td>
					                  <td width="70%" style="text-align:left">
					                  		<select id="status" name='status' class='select_1'style='visibility: visible;width:40%;'>
												<option selected value=''>-----请选择-----</option>
												<option value='1'>有效</option>
												<option value='0'>无效</option>
											</select>
					                  </td>
					                </tr>
								</tbody>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center">
			   <input class="input_button_3" name="" type="button" onclick="saveOrUpdateClassification()" value="保存"/>&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeSaveOrUpdateDiv()" value="取消"/>
			</div>
	</div>
  	
  </body>
</html>
